package thread;

/**
 * @Author Janson
 * @Date 2022/2/24 21:16
 * @Version 1.0
 */
// 静态代理模式总结:
    //真实对象和代理对象都要实现同一个接口
    //代理对象要代理真实对象，即 在代理对象中调用真实对象
public class StaticProxy {
    public static void main(String[] args) {
        //You you = new You();
        //WeddingCompany weddingCompany = new WeddingCompany(you);
        //weddingCompany.happyMarry();
        //下边一行 ，和上边三行功能一样
        new WeddingCompany(new You()).happyMarry();
        //new WeddingCompany(()-> System.out.println("我爱你")).happyMarry();
    }
}
// 结婚接口
interface Marry{
    void happyMarry();
}
//结婚对象  You
class You implements Marry{
    @Override
    public void happyMarry() {
        System.out.println("janson要娶媳妇了。");
    }
}
//代理公司，代理你办理一切事宜
class WeddingCompany implements Marry{
    private Marry target;
    public WeddingCompany(Marry marry) {
        this.target = marry;
    }
    @Override
    public void happyMarry() {
        before();
        target.happyMarry(); //执行真实的对象
        after();
    }
    private void after() {
        System.out.println("结婚后，睡媳妇");
    }
    private void before() {
        System.out.println("结婚前，接媳妇");
    }
}
